package com.green.voluntaryfiling.util;

import java.text.DecimalFormat;
//后续percent方法增加学科subject形参，增加高校录取人数形参accepcted_people形参
//录取人数预测值未加入，暂提高分数预测值占比为40%
//历史科/文科 匹配算法
public class HistorySchoolMatchingUtil {
    public static Double percent(Integer ranking,Integer st_ranking,Double score, Double st_score){
        DecimalFormat df = new DecimalFormat("#0.00");
        Double total_percent=0.0;//总预测值=分数预测值+排位预测值+录取人数预测值
        Double score_percent=0.0;//分数预测值，占比30%
        Double ranking_percent=0.0;//排位预测值，占比60%
        Double accpected_percent=0.0;//录取人数预测值，占比10%

        Double max_score=st_score+30.0;
        Double min_score=st_score-25.0;

        //如果学生分数较高，学生的最高分数为750；
        if(max_score>=750.0){
            max_score=750.0;
        }
        //如果学生分数较低，学生的最低分数为200；
        if(min_score<=200.0){
            min_score=200.0;
        }

        Double top_ranking=0.0;//高排位
        Double bottom_ranking=0.0;//低排位
        //获取学生分数的排位进行筛选，根据位次,
        // 目前只考虑理科的选项（统一理科处理）
        if(st_ranking<=304){
            top_ranking = st_ranking - 15*12.0;
            bottom_ranking = st_ranking +20*12.0;
        }else if(st_ranking<=1838){
            top_ranking = st_ranking - 15*61.0;
            bottom_ranking = st_ranking + 20*61.0;
        }else if(st_ranking<=5977){
            top_ranking = st_ranking - 15*165.0;
            bottom_ranking = st_ranking + 20*165.0;
        }else if(st_ranking<=14069){
            top_ranking = st_ranking - 15*325.0;
            bottom_ranking = st_ranking + 20*325.0;
        }else if(st_ranking<=26463){
            top_ranking = st_ranking - 15*495.0;
            bottom_ranking = st_ranking + 20*495.0;
        }else if(st_ranking<=42854){
            top_ranking = st_ranking - 15*655.0;
            bottom_ranking = st_ranking + 20*655.0;
        }else if(st_ranking<=62789){
            top_ranking = st_ranking - 15*800.0;
            bottom_ranking = st_ranking + 20*800.0;
        }else if(st_ranking<=84452){
            top_ranking = st_ranking - 15*866.0;
            bottom_ranking = st_ranking + 20*866.0;
        }else if(st_ranking<=106995){
            top_ranking = st_ranking - 15*900.0;
            bottom_ranking = st_ranking + 20*900.0;
        }else if(st_ranking<=129279){
            top_ranking = st_ranking - 15*890.0;
            bottom_ranking = st_ranking + 20*890.0;
        }else if(st_ranking<=150994){
            top_ranking = st_ranking - 15*870.0;
            bottom_ranking = st_ranking + 20*870.0;
        }else if(st_ranking<=172171){
            top_ranking = st_ranking - 15*850.0;
            bottom_ranking = st_ranking + 20*850.0;
        }else if(st_ranking<=192277){
            top_ranking = st_ranking - 15*805.0;
            bottom_ranking = st_ranking + 20*805.0;
        }else if(st_ranking<=209895){
            top_ranking = st_ranking - 15*705.0;
            bottom_ranking = st_ranking + 20*705.0;
        }else if(st_ranking<=224459){
            top_ranking = st_ranking - 15*580.0;
            bottom_ranking = st_ranking + 20*580.0;
        }else if(st_ranking<=235771){
            top_ranking = st_ranking - 15*450.0;
            bottom_ranking = st_ranking + 20*450.0;
        }else if(st_ranking<=250001){
            top_ranking = st_ranking - 15*285.0;
            bottom_ranking = st_ranking + 20*285.0;
        }else {
            top_ranking = st_ranking - 15 *285.0;
            bottom_ranking = st_ranking + 20*285.0;
        }


        //处理两种极端情况
        if(top_ranking<=1.0){
            top_ranking = 1.0;
        }
        if(bottom_ranking>=255701.0){
            bottom_ranking=255701.0;
        }
        //如果学校录取最低分数大于最大分数且学校录取最低排位小于top_ranking
        if(score>max_score&&ranking<top_ranking){
            total_percent=0.0;
            return Double.valueOf(df.format(total_percent*100));
        }
        //如果学校录取最低分数大于最大分数且学校录取最低排位大于top_ranking
        if(score<min_score&&ranking>bottom_ranking){
            total_percent=1.0;
            return Double.valueOf(df.format(total_percent*100));
        }

        //处理分数预测值算法
        //如果分数高于录取分数15，则取满分，否则按一定比例扣除
        //如果分数低于录取分数20分，则取0分，否则按一定比例扣除
        if(score<=max_score&&score>=min_score){
            //如果分数高于录取分数15，则取满分，否则按一定比例扣除
            if(max_score-score>=45){
                score_percent=0.40;
            }else if(max_score-score<=15){
                score_percent=0.00;
            }else {
                //此处max_score-score取值范围为15-45
                //暂时乘以0.4，后续改为0.3
                score_percent = ((max_score-score)-15.0)/30 * 0.4;
            }
        }

        //处理排位预测值算法
        if(st_ranking<=304){
            //大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *12.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *12.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/12.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/12.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=1838){
            //大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *61.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *61.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/61.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/61.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=5977){
            //大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *165.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *165.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/165.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/165.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=14069){
            //大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            //如果排位低于12分的排位数，则取满分，否则按一定比例扣除
            if(bottom_ranking-ranking>=29 *325.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *325.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/325.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/325.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }

        }else if(st_ranking<=26463){
            //大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *495.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *495.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/495.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/495.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=42854){
            //800大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *655.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *655.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/655.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/655.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=62789){
            //1000大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *800.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *800.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/800.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/800.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=84452){
            //1150大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *866.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *866.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/866.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/866.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=106995){
            //1200大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *900.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *900.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/900.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/900.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=129279){
            //1250大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *890.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *890.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/890.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/890.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=150994){
            //1200大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *870.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *870.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/870.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/870.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=172171){
            //1150大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *850.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *850.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/850.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/850.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }

        }else if(st_ranking<=192277){
            //1000大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *805.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *805.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/805.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/805.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=209895){
            //900大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *705.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *705.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/705.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/705.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=224459){
            //800大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *580.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *580.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/580.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/580.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=235771){
            //700大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *450.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *450.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/450.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/450.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else if(st_ranking<=25001){
            //600大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *285.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *285.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/285.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/285.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }else {
            //大概排位取值为低于9分  大于12分区间，如果低于9分的排位数以上，则取0.6；大于12分以上则取0.0；否则，按一定比例扣除
            if(bottom_ranking-ranking>=29 *285.0){
                ranking_percent=0.00;
            }else if(bottom_ranking-ranking<=8 *285.0) {
                //如果排位高于9分的排位数，则取满分，否则按一定比例扣除
                ranking_percent = 0.60;
            }else if(ranking<=bottom_ranking&&ranking>=top_ranking){
                ranking_percent = (((Math.abs(ranking-top_ranking)/285.0)-8.0)/21.0)*0.6;
                if( (((Math.abs(ranking-top_ranking)/285.0)-8.0)/21.0)<=0){
                    ranking_percent=0.0;
                }
            }


        }

        //处理学校录取人数预测值


        total_percent = score_percent+ranking_percent+accpected_percent;


        return Double.valueOf(df.format(total_percent*100));
    }
}
